/*
 * Copyright 2008 [rapid-framework], Inc. All rights reserved.
 * Website: http://www.rapid-framework.org.cn
 */

    define("pages/jls_Fjsz/main", [
            "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
            "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
            "../../plugins/artTemplate/artTemplate",
            "../../common/tools",
            "../../common/componts",
            "../../common/kss",
            "../../pages/jls_Fjsz/form",
            "../../pages/jls_Jbxx/JbxxShowHide.html.js",
            "../../pages/jls_Fjsz/FjszShowHide.html.js"
        ],
        function(require) {
            var comonts=require("../../common/componts");
            var fjszForm=require("../../pages/jls_Fjsz/form");
            var tmp=require("../../pages/jls_Jbxx/JbxxShowHide.html");
            var tmpFjsz=require("../../pages/jls_Fjsz/FjszShowHide.html");
            var kss=require("../../common/kss");
            var ryjbxxId="jbxxId";
            var fjszId="fjszId";
            var fjsz="fjsz";
            var selectid;
            var id;
            var jbxx="jbxx";

            var tableInit=function(){
                kss.initJbxxTable(ryjbxxId,{
                    singleSelect:true,
                    url:'/jls_jbxx/jbxxList',
                    detailFormatter : function(index, rowData) {
                        return '<table  style="height:60px;width:100%"><tr><td>户籍地详细地址：'
                            + (rowData.hjszd == null ? ""
                                : rowData.hjszd)
                            + '</td></tr><tr><td>现住地详细地址:'
                            + (rowData.xzd == null ? "" : rowData.xzd)
                            + '</td></tr><tr><td>办案单位:'
                            + (rowData.badw == null ? "" : rowData.badw)
                            + '</td></tr><tr><td>简要案情:'
                            + (rowData.aq == null ? "" : rowData.aq)
                            + '</td></tr></table>'
                    },
                    onDblClickRow:function(rowIndex, rowData){
                        if (rowData.rybh != undefined) {
                            $("input[name='ryRadio']")[rowIndex].checked = true;
                            $("#"+ryjbxxId).datagrid("selectRow", rowIndex);
                            var jbxx=$("#"+ryjbxxId).datagrid('getSelected');
                            fjszForm.show(jbxx,{},refreshTable);

                            $('input').next().find('input[type=text]').css('background-color','#EBEBE4');
                            var myDate = new Date();
                            var str=myDate.toLocaleTimeString();
                        }
                    },
                    onClickRow:function(rowIndex, rowData){
                        if(selectid!=rowData.id){
                            $("input[name='ryRadio']")[rowIndex].checked = true;
                            selectid=rowData.id;
                        }else{
                            $("#"+ryjbxxId).datagrid("unselectRow",rowIndex);
                            $("input[name='ryRadio']")[rowIndex].checked = false;
                            $('#'+ryjbxxId).datagrid('clearSelections');
                            selectid="";
                        }
                    },
                    onSelect:function(rowIndex, rowData){
                        var jbxx = $('#'+ryjbxxId).datagrid('getSelected');
                        var flag = $("input[name='ryRadio']")[rowIndex].checked;
                        if(jbxx && !flag){
                            var rybh = jbxx.rybh;
                            $('#'+fjszId).datagrid('loadData', { total: 0, rows: [] });
                            if (rybh != undefined) {
                                var opts = $("#"+fjszId).datagrid("options");
                                $("#"+fjszId).datagrid("clearSelections");
                                $('#'+fjszId).datagrid('load',{
                                    'rybh': rybh,
                                });
                            }
                        }else {
                            $('#'+fjszId).datagrid('loadData', { total: 0, rows: [] });
                        }
                    },
                    rightmenu:function(){
                    }

                });
                comonts.initTable(fjszId,{
                    title: 'Fjsz',
                    url:"/jls_fjsz/fjszList",
                    columns:[                    	
                        /*{field: 'id',title: 'id',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="idRadio" id="idRadio"' + rowIndex + 'value="' + rowData.id + '" />';}},
                        {field: 'rybh',title: 'rybh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="rybhRadio" id="rybhRadio"' + rowIndex + 'value="' + rowData.rybh + '" />';}},
                        {field: 'fjmc',title: 'fjmc',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="fjmcRadio" id="fjmcRadio"' + rowIndex + 'value="' + rowData.fjmc + '" />';}},
                        {field: 'fjhm',title: 'fjhm',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="fjhmRadio" id="fjhmRadio"' + rowIndex + 'value="' + rowData.fjhm + '" />';}},
                        {field: 'fjqc',title: 'fjqc',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="fjqcRadio" id="fjqcRadio"' + rowIndex + 'value="' + rowData.fjqc + '" />';}},
                        {field: 'fjdj',title: 'fjdj',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="fjdjRadio" id="fjdjRadio"' + rowIndex + 'value="' + rowData.fjdj + '" />';}},
                        {field: 'frxm',title: 'frxm',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="frxmRadio" id="frxmRadio"' + rowIndex + 'value="' + rowData.frxm + '" />';}},
                        {field: 'tsry',title: 'tsry',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="tsryRadio" id="tsryRadio"' + rowIndex + 'value="' + rowData.tsry + '" />';}},
                        {field: 'flag',title: 'flag',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="flagRadio" id="flagRadio"' + rowIndex + 'value="' + rowData.flag + '" />';}},
                        {field: 'jsbh',title: 'jsbh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="jsbhRadio" id="jsbhRadio"' + rowIndex + 'value="' + rowData.jsbh + '" />';}},
                        {field: 'fjlx',title: 'fjlx',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="fjlxRadio" id="fjlxRadio"' + rowIndex + 'value="' + rowData.fjlx + '" />';}},
                        {field: 'state',title: 'state',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="stateRadio" id="stateRadio"' + rowIndex + 'value="' + rowData.state + '" />';}},
                        {field: 'createtime',title: 'createtime',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="createtimeRadio" id="createtimeRadio"' + rowIndex + 'value="' + rowData.createtime + '" />';}},
                        {field: 'operator',title: 'operator',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="operatorRadio" id="operatorRadio"' + rowIndex + 'value="' + rowData.operator + '" />';}},
                        {field: 'scbz',title: 'scbz',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="scbzRadio" id="scbzRadio"' + rowIndex + 'value="' + rowData.scbz + '" />';}},
                        {field: 'blid',title: 'blid',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="blidRadio" id="blidRadio"' + rowIndex + 'value="' + rowData.blid + '" />';}},*/

                        {
                            field : 'id',
                            width : 150,
                            title:'id',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.id== null ? "" : row.id)+'</span>'
                            }},
                        {
                            field : 'rybh',
                            width : 150,
                            title:'人员编号',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.rybh== null ? "" : row.rybh)+'</span>'
                            }},
                        {
                            field : 'fjmc',
                            width : 150,
                            title:'附件名称',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.rybh== null ? "" : row.rybh)+'</span>'
                            }},
                        {
                            field : 'fjhm',
                            width : 150,
                            title:'fjhm',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.fjhm== null ? "" : row.fjhm)+'</span>'
                            }},
                        {
                            field : 'fjqc',
                            width : 150,
                            title:'fjqc',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.fjqc== null ? "" : row.fjqc)+'</span>'
                            }},
                        {
                            field : 'fjdj',
                            width : 150,
                            title:'fjdj',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.fjdj== null ? "" : row.fjdj)+'</span>'
                            }},
                        {
                            field : 'frxm',
                            width : 150,
                            title:'frxm',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.frxm== null ? "" : row.frxm)+'</span>'
                            }},
                        {
                            field : 'tsry',
                            width : 150,
                            title:'tsry',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.tsry== null ? "" : row.tsry)+'</span>'
                            }},
                        {
                            field : 'flag',
                            width : 150,
                            title:'flag',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.flag== null ? "" : row.flag)+'</span>'
                            }},
                        {
                            field : 'jsbh',
                            width : 150,
                            title:'jsbh',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.jsbh== null ? "" : row.jsbh)+'</span>'
                            }},
                        {
                            field : 'fjlx',
                            width : 150,
                            title:'fjlx',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.fjlx== null ? "" : row.fjlx)+'</span>'
                            }},
                        {
                            field : 'state',
                            width : 150,
                            title:'状态',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.state== null ? "" : row.state)+'</span>'
                            }},
                        {
                            field : 'createtime',
                            width : 150,
                            title:'创建时间',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.createtime== null ? "" : row.createtime)+'</span>'
                            }},
                        {
                            field : 'operator',
                            width : 150,
                            title:'负责人',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.operator== null ? "" : row.operator)+'</span>'
                            }},
                        {
                            field : 'scbz',
                            width : 150,
                            title:'scbz',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.scbz== null ? "" : row.scbz)+'</span>'
                            }},
                        {
                            field : 'blid',
                            width : 150,
                            title:'blid',
                            sortable:'true',
                            formatter: function(value,row,index){
                                return '<span title='+value+'>'+(row.blid== null ? "" : row.blid)+'</span>'
                            }},



                        ],
                    detailFormatter:function(index,rowData){
                        return ;
                    },
                    onClickRow:function(rowIndex, rowData){
                        if(id!=rowData.id){
                            $("input[name='fjszRadio']")[rowIndex].checked = true;
                            $('#'+fjszId).datagrid("selectRow", rowIndex);
                            id=rowData.id;
                        }else if(id==rowData.id){
                            $('#'+fjszId).datagrid("unselectRow",rowIndex);
                            $("input[name='fjszRadio']")[rowIndex].checked = false;
                            id="";
                        }
                    },
                    //双击事件
                    onDblClickRow:function(rowIndex, rowData){
                        $("input[name='fjszRadio']")[rowIndex].checked = true;
                        $('#'+fjszId).datagrid("selectRow", rowIndex);
                        id=rowData.id;
                        var jbxx = $('#jbxxId').datagrid('getSelected');
                        fjszForm.show(jbxx,rowData,refreshTable);

                    },

                });
                $('#'+fjszId).datagrid('resize',{
                    height:($(window).height() -320)
                });

            }
            var findFjsz=function(){
                var val = $("#jqjsTree").tree('getSelected');
                var s_rybh = $("#s_rybh").textbox('getValue');
                var s_xm = $("#s_xm").textbox('getValue');
                //人员状态,单选框
                var opts = $('#'+ryjbxxId).datagrid("options");
                opts.url = "/jls_jbxx/jbxxList";
                $('#'+ryjbxxId).datagrid('clearSelections');
                $('#'+ryjbxxId).datagrid('load',{
                	'xm':s_xm,
                    'rybh':s_rybh,
                });
            }
            var initJsTree=function(){
                kss.initJsTree("jqjsTree","jbxxId",{});
            }
            var bindAction=function(){
                $("#fjsz_search").on("click",function(){
                    findFjsz();
                });
                $("#fjsz_add").on("click",function(){
                    var ryjbxx=$("#"+ryjbxxId).datagrid('getSelected');
                    if(ryjbxx){
                        fjszForm.show(ryjbxx,{},refreshTable);
                    }else{
                        $.messager.alert("提示","请选择要新增的记录!","info");
                    }
                });
                $("#fjsz_update").on("click",function(){
                    var ryjbxx=$("#"+ryjbxxId).datagrid('getSelected');

                    if(ryjbxx){
                        fjszForm.show(ryjbxx,refreshTable,{});
                        $('#rybhId').next().find('input[type=text]').css('background-color','#ebebe4');
                        $('#ryxmId').next().find('input[type=text]').css('background-color','#ebebe4');
                        $('#jshId').next().find('input[type=text]').css('background-color','#ebebe4');
                    }else{
                        $.messager.alert("提示","请选择要修改的记录!","info");
                    }
                });

                $(window).keydown(function(event) {
                    if (event.keyCode == 13) {
                        findfjsz();
                    }
                });
                comonts.ShowHide(jbxx,tmp);
                comonts.ShowHide(fjsz,tmpFjsz);
                $("#fjsz_print").on("click",function(){
                    var label="jls_fjsz";
                    var name="jls_fjsz";
                    var rybh=$("#"+ryjbxxId).datagrid('getSelected').rybh;
                    var url=comonts.getReportUrl(true,label,name,'rybh%3d'+rybh);
                    console.info(url);
                    addTab("Fjsz",url);
                });

            }
            var refreshTable=function(data){
                $('#'+fjszId).datagrid('reload',{rybh:$('#'+ryjbxxId).datagrid('getSelected').rybh});
            }


            var initView=function(){
                tableInit();
                bindAction();
                initJsTree();

            }


            initView();
        });
